package cn.tedu.shopol.taojin.controller;

import cn.tedu.shopol.taojin.dto.RegisterClientDTO;
import cn.tedu.shopol.taojin.ex.InsertException;
import cn.tedu.shopol.taojin.ex.InvalidParameterException;
import cn.tedu.shopol.taojin.ex.PhoneDuplicateException;
import cn.tedu.shopol.taojin.service.IUserService;
import cn.tedu.shopol.taojin.util.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author tedu.cn
 * @since 2020-12-08
 */
@RestController
@RequestMapping("/taojin/user")
@Slf4j
public class UserController {

    @Autowired
    IUserService userService;

    @PostMapping("/register/client")
    public R registerClient(RegisterClientDTO registerClientDTO){
        R r = new R();
        try {
            userService.registerClient(registerClientDTO);
            r.setState(1);
            r.setMessage("注册成功!");
        }catch (PhoneDuplicateException e){
            System.out.println("注册失败!手机号已被注册!");
        }catch (InsertException e){
            System.out.println("注册失败!服务器繁忙,请稍后重试...");
        }catch (InvalidParameterException e){
            System.out.println("注册失败!格式错误,无法注册!");
        }
        return r;
    }
}
